package com.app.designpatternslearn.behavior.iteratorpattern.code

class SubContainer<T> : Container<T> {

    private val data = arrayListOf<T>()

    fun addElement(t: T) {
        data.add(t)
    }


    override fun getIterator(): Iterator<T> = SubIterator()

    inner class SubIterator : Iterator<T> {
        private var index: Int = 0
        override fun hasNext(): Boolean = index < data.size

        override fun next(): T? = if (hasNext()) data[index++] else null

    }

}